package com.woniuxy.microsysserver.mapper;

import com.woniuxy.microsysserver.bean.AdminInfo;
import com.woniuxy.microsysserver.bean.RoleInfo;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface RoleMapper {

    @Select("select id,role_name as roleName,role_des as roleDes,create_time as createTime,state,useing,permit from role_info where id = #{id}")
    RoleInfo findById(Integer id);

    /**
     * 查找所有
     * @return
     */
    @Select("select id,role_name as roleName,role_des as roleDes,create_time as createTime," +
            "useing,count,permit from role_info where state = 1")
    @ResultType(value = List.class)
    List<RoleInfo> findAll();

    /**
     * 逻辑删除
     * @param id
     */
    @Update("update role_info set state = 2 where id = #{id}")
    void delete(Integer id);

    /**
     * 编辑
     * @param roleInfo
     */
    void updateRole(@Param("r") RoleInfo roleInfo);

    /**
     * 新增角色
     * @param roleInfo
     */
    @Insert("insert into role_info (role_name,role_des,create_time,useing,state,count,permit)" +
            "values (#{r.roleName},#{r.roleDes},now(),1,1,0,'/sh/cs')")
    void add(@Param("r")RoleInfo roleInfo);


    @Select("select login_name as loginName,admin_name as adminName,phone from admin_info where fk_role = #{id} and state = 1 ")
    List<AdminInfo> findByRoleId(Integer id);


    @Update("update role_info set permit = #{p} where id = #{id}")
    void changePermit(@Param("id") Integer id,@Param("p") String permit);
}
